from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Chrome(executable_path='../chromedriver.exe')
# 以某一个关键字，爬取拉钩岗位需求描述数据
keyword = 'python'
url = "https://www.lagou.com/"

driver.get(url)
time.sleep(1)
xpathQuanguo = '//*[@id="changeCityBox"]/p[1]/a'
el1  = driver.find_element(By.XPATH,xpathQuanguo)
el1.click()
time.sleep(1)
xpathInput = "//input[@id='search_input']"
el2 = driver.find_element(By.XPATH,xpathInput)
# # 设置文本内容，键盘输入回车
el2.send_keys('python'+Keys.ENTER)
time.sleep(1)

# 分页获取每一页的数据
# 获取到第一条职位的标题数据
a = driver.find_element(By.XPATH,'//*[@id="openWinPostion"]')

print(a.text)
a.click()
time.sleep(1)
# 获取职位描述信息
xpathStr = '//*[@id="job_detail"]/dd[2]/div'

# 转到新页面
driver.switch_to.window(driver.window_handles[-1])
# 在详情页中，获取岗位需求详情
div = driver.find_element(By.XPATH,xpathStr)
print(div.text)
driver.close()
driver.switch_to.window(driver.window_handles[0])


time.sleep(11)
# driver.close()





